﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OptixDotNet;
using OptixDotNet.Math;
using RayDen.Library.Entity.Frames;
using RayDen.Optix.Engine.Components;
using RayDen.Optix.Engine.Managers;
using RayDen.Optix.Engine.Scene.Entities;

namespace RayDen.Optix.Engine.Engines
{
    public class RayTracer : RenderEngine
    {
        private string lightPrefix = "lt";
        internal float yAvg = 0.1625f;
        internal float yMax = 2.5f;
        internal float apertureSize = 0.05f;

        private RdfManager sceneManager;

        internal PreethamSkyModel skyModel;
        private float SceneEpsilon = 1e-4f;
        private uint mFrame;

        public RayTracer()
        {
            this.CreateContext();
            sceneManager = new RdfManager(Context);
        }

        public override void OpenFrame(string framePath)
        {
            base.OpenFrame(framePath);
            sceneManager.OpenFrame(framePath);
            this.Scene = sceneManager.Scene;
        }

        public override void OpenFrame(FrameDescription frame)
        {
            sceneManager.OpenFrame(frame);
            this.Scene = sceneManager.Scene;
            this.Settings.ImageWidth = sceneManager.width;
            this.Settings.ImageHeight = sceneManager.height;
        }


        public override void Initialize(Action<BoundingBox> setCamera, params object[] parameters)
        {
            base.Initialize(setCamera, parameters);
            string rayGenPath = PtxDir + ("raytracer.cu.ptx");
            string shaderPath = PtxDir + ("raytracer.cu.ptx");


            var Context = base.Context;
            var Width = (int)parameters[1];
            var Height = (int)parameters[2];

            var desc = new BufferDesc()
            {
                Width = (uint)Width,
                Height = (uint)Height,
                Format = Format.Float3,
                Type = BufferType.InputOutput
            };
        }
    }
}
